package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.DefCompany;
import com.ruoyi.system.service.IDefCompanyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 单位管理Controller
 * 
 * @author ruoyi
 * @date 2024-10-09
 */
@RestController
@RequestMapping("/system/company")
public class DefCompanyController extends BaseController
{
    @Autowired
    private IDefCompanyService defCompanyService;

    /**
     * 查询单位管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:company:list')")
    @GetMapping("/list")
    public TableDataInfo list(DefCompany defCompany)
    {
        startPage();
        List<DefCompany> list = defCompanyService.selectDefCompanyList(defCompany);
        return getDataTable(list);
    }

    /**
     * 导出单位管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:company:export')")
    @Log(title = "单位管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DefCompany defCompany)
    {
        List<DefCompany> list = defCompanyService.selectDefCompanyList(defCompany);
        ExcelUtil<DefCompany> util = new ExcelUtil<DefCompany>(DefCompany.class);
        util.exportExcel(response, list, "单位管理数据");
    }

    /**
     * 获取单位管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:company:query')")
    @GetMapping(value = "/{companyId}")
    public AjaxResult getInfo(@PathVariable("companyId") Integer companyId)
    {
        return success(defCompanyService.selectDefCompanyByCompanyId(companyId));
    }

    /**
     * 新增单位管理
     */
    @PreAuthorize("@ss.hasPermi('system:company:add')")
    @Log(title = "单位管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DefCompany defCompany)
    {
        return toAjax(defCompanyService.insertDefCompany(defCompany));
    }

    /**
     * 修改单位管理
     */
    @PreAuthorize("@ss.hasPermi('system:company:edit')")
    @Log(title = "单位管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DefCompany defCompany)
    {
        return toAjax(defCompanyService.updateDefCompany(defCompany));
    }

    /**
     * 删除单位管理
     */
    @PreAuthorize("@ss.hasPermi('system:company:remove')")
    @Log(title = "单位管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{companyIds}")
    public AjaxResult remove(@PathVariable Integer[] companyIds)
    {
        return toAjax(defCompanyService.deleteDefCompanyByCompanyIds(companyIds));
    }

    @PostMapping("import")
    @Log(title = "得分规则", businessType = BusinessType.IMPORT)
    public AjaxResult importData(MultipartFile file) {
        return success(defCompanyService.importDefCompany(file));
    }
}
